#@layout()

#define content()

<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',border:true">
        #if(resourceList != null)
        <div class="easyui-panel" title="工具栏" style="width:100%;padding:10px;" data-options="iconCls:'icon-application_form'">
            #for(resource : resourceList)
            <a href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'#(resource.icon)',plain:true" id='#(resource.url)'>#(_res.get(resource.resourceName))</a>
            #end
        </div>
        <br>
        #end

        <div class="easyui-panel" title="配置信息" style="width:100%;padding:10px;"
             data-options="iconCls:'icon-application_form'">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th tabindex="0" data-field="facet_name" style="">
                        <div class="th-inner sortable both">#(_res.get('facet.form.prop.name'))</div>
                        <div class="fht-cell"></div>
                    </th>
                    <th tabindex="0" data-field="facet_name" style="">
                        <div class="th-inner sortable both">属性说明</div>
                        <div class="fht-cell"></div>
                    </th>
                    <th tabindex="0" data-field="facet_name" style="">
                        <div class="th-inner sortable both">#(_res.get('facet.form.prop.value'))</div>
                        <div class="fht-cell"></div>
                    </th>
                </tr>
                </thead>
                <tbody>

                #--=========================== 循环遍历属性开始 ==============================--#
                <input type="hidden" name="tenantId" id="tenantId" value="#(tenantId??)">
                #for(tenantConfig : tenantConfigs)
                <tr>
                    <td>
                        <a href="javascript:void(0);"
                           title="#(_res.get(tenantConfig.configCname))"
                           class="easyui-tooltip">#(tenantConfig.configEname)</a>
                    </td>
                    <td>
                        #(_res.get(tenantConfig.configCname))
                    </td>
                    <td>
                        #if(tenantConfig.dataType == 'boolean')
                        <select name="#(tenantConfig.tcId)" id="#(tenantConfig.tcId)"
                                ename="#(tenantConfig.configEname)"
                                onchange="editText(this)" style="width: 400px;" dataType="#(tenantConfig.dataType)"
                                regex="#(tenantConfig.regex)" errorMsg="#(tenantConfig.errorMsg)">
                            <option value="true" #(tenantConfig.configValue == 'true' ? 'selected':'')>true</option>
                            <option value="false" #(tenantConfig.configValue == 'false'  ? 'selected':'')>false
                            </option>
                        </select>

                        #elseif(tenantConfig.dataType == 'string')
                        <input id="#(tenantConfig.tcId)" type="text" ename="#(tenantConfig.configEname)"
                               value="#(tenantConfig.configValue)"
                               onchange="editText(this)" style="width: 400px;" dataType="#(tenantConfig.dataType)"
                               regex="#(tenantConfig.regex)" errorMsg="#(tenantConfig.errorMsg)"/>





                        #elseif(tenantConfig.dataType == 'json')





                        <select name="#(tenantConfig.tcId)" id="#(tenantConfig.tcId)"
                                ename="#(tenantConfig.configEname)"
                                onchange="editText(this)" style="width: 400px;" dataType="#(tenantConfig.dataType)"
                                regex="#(tenantConfig.regex)" errorMsg="#(tenantConfig.errorMsg)">




                            <script>

                                function isJsonString(str) {
                                    try {
                                        if (typeof JSON.parse(str) == "object") {
                                            return true;
                                        }
                                    } catch (e) {
                                    }
                                    return false;
                                }
                            </script>
                            <script>


                                var ob, htmlOpton=[];

                                if(('#(tenantConfig.configEname)')==("webauthn.authenticator.selection.criteria.authenticator.attachment"))
                                {
                                    ob = '["direct","indirect","none"]';
                                }else if (('#(tenantConfig.configEname)')==("webauthn.authenticator.selection.criteria.user.verification"))
                                {
                                    ob = '["required","preferred","discouraged"]';
                                }

                                var optionlist =JSON.parse(ob);
                                for (var optionNode in optionlist) {
                                    var htmlOptonNode = '<option value='+optionlist[optionNode]+'>'+optionlist[optionNode]+'</option>';
                                    htmlOpton.push(htmlOptonNode);
                                    document.getElementById("#(tenantConfig.tcId)").innerHTML = htmlOpton.join('');

                                }




                                var optionSet =  document.getElementById("#(tenantConfig.tcId)")
                                if (!isJsonString('#(tenantConfig.configValue)'))
                                {
                                    for (var optionSetIndex in optionSet)
                                        if (optionSet[optionSetIndex].value == '#(tenantConfig.configValue)')
                                            optionSet[optionSetIndex].selected = true;
                                }

                            </script>
                        </select>

                        #elseif(tenantConfig.dataType == 'number')
                        <input id="#(tenantConfig.tcId)" type="text" ename="#(tenantConfig.configEname)"
                               value="#(tenantConfig.configValue)"
                               onchange="editText(this)" style="width: 400px;" dataType="#(tenantConfig.dataType)"
                               regex="#(tenantConfig.regex)" errorMsg="#(tenantConfig.errorMsg)"/>
                        #end
                    </td>
                </tr>
                #end
                #--=========================== 循环遍历属性结束 ==============================--#

                </tbody>
            </table>
        </div>
    </div>


</div>

#end


#define css()

#end


#define js()

<script type="text/javascript">

    function editText(t) {
        var element = $(t);
        var dataType = element.attr("dataType");
        var regex = element.attr("regex");
        var errorMsg = element.attr("errorMsg");
        var flag = true;

        if (regex !== '' && regex !== 'null') {//如果设置了正则表达式，则对内容进行验证
            regex = eval("(" + regex + ")");
            flag = regex.test(element.val());
        }


        if (flag) {

            var url = contextRootPath + '/tenantConfig/edit';
            var params = {
                "tenantConfig.config_value": element.val(),
                "tenantConfig.tc_id": element.attr("id"),
                "tenantConfig.tenant_id": $("#tenantId").val(),
                "tenantConfig.config_ename": element.attr("ename")
            };

            $.post(url, params, function (result) {
                $.messager.alert('提示', result.message);
            }, 'json');

            $('.error_sty').removeClass('error_sty').tooltip('destroy');

        } else {
            $.messager.alert('提示框', errorMsg);
            element.addClass('error_sty');
            element.tooltip({
                position: 'top',
                content: errorMsg
            });
        }
    }

</script>

#end



